public class Date {
    //属性在堆上存储
    public int year;
    public int month;
    public int day;

    //构造方法     在new Date自动调用
    public Date(){
        year = 2024;
        month = 11;
        day = 29;
        System.out.println("调用构造方法");
    }

    public Date(int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
        System.out.println("调用第二个构造方法");
    }


    //方法在方法区存储
    public void setDate(int year, int month ,int day){
        //通过·this关键字，表明哪些是成员变量
        this.year = year;
        this.month = month;
        this.day = day;
    }
    public void printDate(){
        System.out.println(year + "-" +  month + "-" + day);
    }

    public static void main(String[] args) {
        Date date = new Date();
        date.setDate(2024,11,29);
        date.printDate();

        Date date1 = new Date();
        date1.setDate(2025,6,11);
        date1.printDate();

        Date date2 = new Date(2024, 12, 5);
        date2.printDate();
    }
}
